Class BinarySearchTree<T extends TreeNodeInfo>


  • public class BinarySearchTree<T extends TreeNodeInfo>
    extends java.lang.Object
    • Constructor Detail

      • BinarySearchTree

        public BinarySearchTree()
        Create an empty BinarySearchTree.
      • BinarySearchTree

        public BinarySearchTree​(boolean dup)
    • Method Detail

      • allows_duplicates

        public boolean allows_duplicates()
      • isEmpty

        public boolean isEmpty()
        Is the BinarySearchTree empty?
        Returns:
        true if empty, false otherwise
      • clear

        public void clear()
      • add

        public void add​(T info)
        Addd a new Tree Node with the given j index and q value
        Parameters:
        info - the key
      • add

        private void add​(T info,
                         TreeNode<T> p)
        Recursive implementation of add.
        Parameters:
        info - the key
        p - the current top Tree Node
      • getVal

        public java.lang.Double getVal​(T info)
      • get

        public T get​(T info)
      • set

        public void set​(T info)
      • contains

        public boolean contains​(T info)
        Is the specified ElemntType in the BinarySearchTree?
        Parameters:
        info - the key
        Returns:
        true if it is contained, false otherwise
      • contains

        private boolean contains​(T info,
                                 TreeNode<T> p)
      • toString

        public java.lang.String toString()
        Gets an inorder String representation of the BinarySearchTree.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the BinarySearchTree as a String
      • toString

        private java.lang.String toString​(TreeNode<T> p)
        Recursive implementation of inorder toString.
        Parameters:
        p - the current TreeNode to print and recursive parameter
        Returns:
        the BinarySearchTree as a String
      • getMin

        public T getMin()
      • getMax

        public T getMax()
      • remove

        public void remove​(T info)
      • getHeight

        public int getHeight()
      • getHeight

        private int getHeight​(TreeNode<T> p)
      • DSW

        public void DSW()
      • createBackbone

        private void createBackbone()
        Time complexity: O(n)
      • createPerfectBST

        private void createPerfectBST()
        Time complexity: O(n)
      • greatestPowerOf2LessThanN

        private int greatestPowerOf2LessThanN​(int n)
        . Time complexity: log(n)
        Parameters:
        n - the inout number
        Returns:
        the greatest power of 2 less than N
      • MSB

        public int MSB​(int n)
        Return the index of most significant set bit: index of least significant bit is 0. Time complexity: log(n)
        Parameters:
        n - the input number
        Returns:
        the index of most significant set bit
      • makeRotations

        private void makeRotations​(int bound)
      • asList

        public java.util.List<T> asList()
      • asList

        private void asList​(java.util.List<T> l,
                            TreeNode<T> p)